<?php 

function  replatestring($str,$html)
{
	$str= trim($str);
	$str =  str_replace("'","&#146",$str);
	//$str =  str_replace(CHR(92),"",$str);
	$str =  str_replace(CHR(34),"&quot;",$str);	
	$str =  str_replace(CHR(13),"",$str);		
	foreach (count_chars($str, 1) as $i => $val)
	{
	   if($i="  ")
	   {
	   		for($j=0; $j<$val; $j++)
			{
				$str =  str_replace("  "," ",$str);
			}
	   }
	}
	if($html==false)
	{
		//$str =  strip_tags($str);
		$str =  str_replace("<","&lt;",$str);
		$str =  str_replace(">","&gt;",$str);
	}
	else
	{
		$str =  str_replace(CHR(10),"<br/>",$str);
	}
	$str =  str_replace("<script>","",$str);
	$str =  str_replace("</script>","",$str);
	return $str;
}
?>